package com.ler.action;

import com.alibaba.fastjson.JSONObject;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.ide.CopyPasteManager;
import com.ler.action.entity.MavenJsonBean;
import com.ler.action.util.GradleParser;
import com.ler.action.util.SelectUtil;
import java.awt.datatransfer.StringSelection;

/**
 * @author lww
 */
public class Gradle2MavenAction extends AnAction {

    @Override
    public void actionPerformed(AnActionEvent e) {
        //获取当前在操作的工程上下文
        //Project project = e.getData(PlatformDataKeys.PROJECT);
        String data = SelectUtil.getSelectString(e);
        if (data == null) {
            return;
        }
        MavenJsonBean bean = GradleParser.parseGradle(data);
        String xml = GradleParser.jsonToXml(JSONObject.toJSONString(bean));
        CopyPasteManager.getInstance().setContents(new StringSelection(xml));
        //Messages.showMessageDialog(project, "转换成功，已复制，去粘贴吧！", "Success", Messages.getInformationIcon());
    }

}
